<template>
  <div class="children">
    <div class="music-list">
      <van-list
        v-model="loading"
        :finished="finished"
        finished-text="没有更多了"
        @load="onLoad"
      >
        <div
          class="van-cell list-item"
          v-for="(item, index) in list"
          :key="index"
          @click="details(item.id)"
        >
          <div class="pic">
            <img :src="item.img" alt="" />
          </div>
          <div class="list-info">
            <p class="info-name">{{ item.name }}</p>
            <p class="list-detail">
              <span>{{ item.time }}</span>
              <span>{{ item.diqu }}</span>
            </p>
            <div class="info-tag">
              <p class="tag-item" v-for="(ele, i) in item.tagList" :key="i">
                {{ ele }}
              </p>
            </div>
            <p class="info-price">
              ¥{{ item.price }}
              <span>起</span>
            </p>
          </div>
        </div>
      </van-list>
    </div>
  </div>
</template>

<script>
import instance from "../../request/api";
export default {
  name: "Children",

  data() {
    return {
      list: [],
      loading: false,
      finished: false,

      arrs: [],
    };
  },

  mounted() {
    this.$nextTick(function () {
      this.getData();
    });
  },

  methods: {
    async getData() {
      let { data } = await instance.get("/home.json");

      this.list = data.home[5].children;
    },
    onLoad() {
      setTimeout(() => {
        this.arrs.forEach((item) => {
          this.list.push(item);
        });

        this.loading = false;
        if (this.list.length >= 10) {
          this.finished = true;
        }
      }, 1000);
    },
    details(id) {
      let index = this.list.find((item) => {
        return item.id == id;
      });
      this.$router.push({
        path: "/particulars",
        query: { id: id },
      });
      console.log(1);
      localStorage.setItem("particulars", JSON.stringify(index));
    },
  },
};
</script>

<style lang="less" scoped>
.children {
  width: 100%;
  overflow: hidden;
  position: relative;
  padding-top: 33px;
  box-sizing: border-box;
  margin-bottom: 50px;

  .music-list {
    width: 100%;
    overflow: hidden;
    position: relative;
    .list-item {
      width: 100%;
      padding: 0 22px;
      box-sizing: border-box;
      display: flex;
      margin-bottom: 33px;
      .pic {
        width: 118px;
        height: 157px;
        margin-right: 19px;
        background: #f8f8f8;
        border-radius: 6px;
        overflow: hidden;
        img {
          width: 100%;
          height: 100%;
        }
      }
      .list-info {
        width: calc(100% - 138px);
        p {
          margin: 0;
        }
        .info-name {
          font-size: 17px;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          height: 44px;
          line-height: 22px;
        }
        .list-detail {
          font-size: 12px;
          color: #aaa;
          margin: 8px 0;
          span {
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
          }
        }

        .info-tag {
          display: flex;
          align-items: center;
          flex-wrap: wrap;
          .tag-item {
            background: #f8f8f8;
            border-radius: 55px;
            font-size: 11px;
            color: #bbb;
            height: 22px;
            line-height: 22px;
            padding: 0 11px;
            margin: 5px 5px 0 0;
          }
        }
        .info-price {
          font-size: 17px;
          margin-top: 8px;
          span {
            font-size: 11px;
            margin-left: 0;
          }
        }
      }
    }
  }
}
</style>